<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>ws client demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="socket.io.js"></script>
    <script>
        // var ws = new io("http://m-test.mingyuanyun.com:8181",
        //     {
        //         extraHeaders: {
        //             Origin: '*'
        //         }
        //     }
        // );
        // // io.set('transports', ['websocket', 'xhr-polling', 'jsonp-polling', 'htmlfile', 'flashsocket']);
        // ws.on('connect', (data) => {
        //     console.log(ws.id);
        // });
        // ws.on('push', (data) => {
        //     appendText(data);
        // });
        // ws.on('register', (data) => {
        //     appendText(data);
        // });
        // ws.on('update_one_program', (data) => {
        //     appendText(data);
        // });
        // ws.on('update_two_program', (data) => {
        //     appendText(data);
        // });
        // ws.on('update_three_program', (data) => {
        //     appendText(data);
        // });
        // ws.on('update_total_program', (data) => {
        //     appendText(data);
        // });

        // ws.onopen = function (evt) {
        //     appendText("Connection open ...");
        //     ws.send("Hello WebSockets!");
        // };

        // ws.onmessage = function (evt) {
        //     var message = evt.data;
        //     if (message.indexOf("connect success") != -1) {
        //         pageId = message.replace("connect success:", "")
        //     }
        //     appendText("Received Message: " + evt.data);
        // };

        // ws.onclose = function (evt) {
        //     appendText("Connection closed.");
        // };

        var testSend = function (value) {
            ws.send('news'.value);
        }

        var appendText = function (text) {
            var c = document.getElementById('txt_area');
            c.value = text + "\r\n" + c.value;
        }

        // var sendT = function () {
        //     ws.send(pageId + ':test');
        // }

        // var closeT = function () {
        //     ws.close();
        // }

        //
        var run1 = function () {
            console.log(1);
            var xhr = new XMLHttpRequest();


            xhr.open('post', 'http://localhost:6789/hr/program-one');
            // xhr.open('post', 'http://m-test.mingyuanyun.com/hr-project-api/hr/program-one');
            // xhr.open('get', 'http://localhost:6789/demo/get');

            xhr.setRequestHeader("Content-type", "application/json");
            //发送请求
            xhr.send();
        }

        var run2 = function () {
            var xhr = new XMLHttpRequest();

            xhr.open('post', 'http://localhost:6789/hr/program-two');
            // xhr.open('post', 'http://m-test.mingyuanyun.com/hr-project-api/hr/program-two');
            // xhr.open('get', 'http://localhost:6789/demo/get');

            xhr.setRequestHeader("Content-type", "application/json");
            //发送请求
            xhr.send();
        }

        var run3 = function () {
            var xhr = new XMLHttpRequest();

            xhr.open('post', 'http://localhost:6789/hr/program-three');
            // xhr.open('post', 'http://m-test.mingyuanyun.com/hr-project-api/hr/program-three');
            // xhr.open('get', 'http://localhost:6789/demo/get');

            xhr.setRequestHeader("Content-type", "application/json");
            //发送请求
            xhr.send();
        }

        var initGame = function () {
            console.log('initGame');
            var xhr = new XMLHttpRequest();

            xhr.open('get', 'http://localhost:6789/hr/game-begin');
            // xhr.open('get', 'http://m-test.mingyuanyun.com/hr-project-api/hr/game-begin');
            // xhr.open('get', 'http://localhost:6789/demo/get');

            xhr.setRequestHeader("Content-type", "application/json");
            //发送请求
            xhr.send();
        }

        var getGame = function () {
            var xhr = new XMLHttpRequest();

            xhr.open('get', 'http://localhost:6789/hr/game-progress');
            // xhr.open('get', 'http://m-test.mingyuanyun.com/hr-project-api/hr/game-progress');
            // xhr.open('get', 'http://localhost:6789/demo/get');

            xhr.setRequestHeader("Content-type", "application/json");
            //发送请求
            xhr.send();
        }
    </script>
</head>

<body>
    <textarea id="txt_area" rows="10" style="width:100%"></textarea>

    <button onclick="sendT();">click send</button>
    <button onclick="closeT();">click close</button>

    <div>
        <div style="width:50%">
            <div style="width:85%;">
                项目1
                <text id="p1"></text>
                项目2
                <text id="p2"></text>
                项目3
                <text id="p3"></text>
            </div>

            <button click="run1();">
                run1
            </button>
            <button click="run2();">
                run2
            </button>
            <button click="run3();">
                run3
            </button>
            <button click="initGame();">
                begin
            </button>
            <button click="getGame();">
                get
            </button>
        </div>
        <div style="width:50%">

        </div>
    </div>

</body>

</html>